<template>
  <li @mouseenter="enterHandle" @mouseleave="leaveHandle">
    <label>
      <input type="checkbox" v-bind:checked="todo.isDone" @change="updeleteTodo(todo.id)"/>
      <span :class="todo.isDone ? 'active' : ''">{{todo.todoName}}</span>
    </label>
    <button class="btn btn-danger" :style="styleObj" @click="deleteTodo(todo.id)">删除</button>
  </li>
</template>

<script>
import {mapMutations,mapState} from 'vuex'

export default {
  props:['todo'],

  data(){
    return{
      styleObj:{
        display:'none'
      }
    }
  },

  computed:{
     ...mapState(['todoList']),
  },
  updated(){
      localStorage.setItem('todos',JSON.stringify(this.todoList))
  },

  methods:{
    enterHandle(){
      this.styleObj.display = 'block'
    },
    leaveHandle(){
      this.styleObj.display = 'none'
    },
    ...mapMutations(['updeleteTodo']),
    ...mapMutations(['deleteTodo'])
  },
  
}
</script>

<style>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li:hover {
  display: block;
}

li label {
  /* display:flex;
  align-items: center; */
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li label span.active {
  color: #ccc;
  text-decoration: line-through;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>
